/*
 * zoj 3998 . How Many Sets II
 * 题目网址： https://zoj.pintia.cn/problem-sets/91827364500/problems/91827369035
 */

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

/*
 * 模板说明
 * data_type：数据类型 
 */

typedef long long data_type; 

/*
 * 求a的e次方模mod的值
 */
data_type power_mod(data_type a, data_type e, int mod){
	data_type p = 1;
	while(e){
		if(e & 1){
			p = (p * a) % mod;
		}
		a = (a * a) % mod;
		e >>= 1;
	}
	return p;
}

class Lucas{

private:
	//从n个元素取m个元素的组合数对p取模,p是素数
	data_type c(int n, int m, int p){
		if(p <= 1) return 0;
		data_type s = 1;
		for(int i = 1; i <= m; i++){
			s = (s * (n - i + 1)) % p;
			s = (s * power_mod(i, p - 2, p)) % p;
		}
		return s;
	}
public:

	// lucas公式c(n,m)%p = (c(n/p,m/p) * c(n%p, m%p))%p
	data_type run(int n, int m, int p){
		if(n < p){
			return c(n, m, p);
		}
		data_type s;
		s = run(n/p, m/p, p);
		s = (s * c(n%p, m%p, p)) % p;
		return s;
	}

};

int main(int argc, char* argv[])
{
	Lucas lucas;
	int n, m, p;
	while(scanf("%d%d%d", &n, &m, &p) != EOF){
		cout << lucas.run(n - m + 1, m, p) << endl;
	}
    return 0;
}
